# docker build -t registry.cn-shanghai.aliyuncs.com/victor01/remix-demo:master .
# docker push registry.cn-shanghai.aliyuncs.com/victor01/remix-demo:master
# docker run -d --name remix -p 3000:3000 -e NODE_ENV=production registry.cn-shanghai.aliyuncs.com/victor01/remix-demo:master
# Note: If your NODE_ENV isn't set to `production` then you'll need to update the file `server.js` with this enviroment
#       to avoid import vite in docker environment
#       because it's built with `pnpm prune --prod` which will remove devDependencies

# Base node
FROM m.daocloud.io/node:22.11.0-alpine3.20 as base
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm

# Install dependencies
FROM base as deps
WORKDIR /myapp
ADD package.json ./
RUN pnpm install

# Build the app
FROM base as build
WORKDIR /myapp
ADD . .
RUN rm -rf node_modules && rm -f pnpm-lock.yaml
COPY --from=deps /myapp/node_modules /myapp/node_modules
COPY --from=deps /myapp/pnpm-lock.yaml /myapp/pnpm-lock.yaml
RUN pnpm run build
RUN pnpm prune --prod

# Finally, build the server
FROM base
WORKDIR /myapp
COPY --from=build /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/build/server /myapp/build/server
COPY --from=build /myapp/build/client /myapp/build/client
ADD package.json server.js ./
ENV NODE_ENV=${NODE_ENV}
CMD ["node", "./server.js"]
